package com.example.demo.api.controller;

import com.example.demo.service.GreetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ApiController {

    @Autowired
    private GreetingService greetingService;

    @GetMapping("/")
    public String home(Model model) {
        model.addAttribute("message", greetingService.getWelcomeMessage());
        return "index";
    }

    @GetMapping("/api/hello")
    @ResponseBody
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return greetingService.getGreeting(name);
    }

    @GetMapping("/api/info")
    @ResponseBody
    public String info() {
        return greetingService.getInfo();
    }
}